package cn.edu.bupt.ch9_1_publisher.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicRabbitConfig {
    @Bean
    public Queue beijingQueue() {
        return new Queue("beijing");
    }

    @Bean
    public Queue shanghaiQueue() {
        return new Queue("shanghai");
    }

    @Bean
    public Queue newsQueue() {
        return new Queue("news");
    }

    @Bean
    public Queue weatherQueue() {
        return new Queue("weather");
    }

    @Bean
    TopicExchange exchange() {

        return new TopicExchange("topicExchange");
    }

    @Bean
    Binding beijingBinding() {

        return BindingBuilder.bind(beijingQueue()).to(exchange()).with("beijing.#");
    }

    @Bean
    Binding shanghaiBinding() {
        return BindingBuilder.bind(shanghaiQueue()).to(exchange()).with("shanghai.#");
    }

    @Bean
    Binding newsBinding() {
        return BindingBuilder.bind(newsQueue()).to(exchange()).with("#.news");
    }

    @Bean
    Binding weatherBinding() {
        return BindingBuilder.bind(weatherQueue()).to(exchange()).with("#.weather");
    }

}
